<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
      <%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script src="${basePath}commonJs/jquery.ztree.all.js"></script>
<script language="javascript" src="${basePath }commonJs/verify.js"></script>
<title>嘉童游乐中心-供应商信息</title>
<script type="text/javascript">
var updateFlag;
var deleteFlag;
var nowBranId="${fkBranId}";
$(document).ready(function(){
	updateFlag=isVerify("${basePath}", "supply:update");
	deleteFlag=isVerify("${basePath}", "supply:delete");
	 initParams();
});
//初始化参数
function initParams() {
	$("#pageNo").val("1");
	$("#pageSize").val("8");
	var myform = $("#supplyInfo");
	var pagebean = new PageBean(myform);
	pagebean.setTableId("showData");
	pagebean.setFootId("foot");
	pagebean.setCallback(showData);
	setPagebeanObj(pagebean); //全局化pageBean对象
	pagebean.doPage();  //执行分页
}
//展示数据
function showData(result){
	trimJsonArray(result);
	$(result).each(function(index,item){
      	var html='<tr><td>'+(index+1)+'</td>';
      	//<a href="#" onclick="forwardToUpdate(this);" pkSupId='+item.pkSupId+'>'+item.pkSupId+'</a>
      	//<input type="button" class="btn_l" onclick="deleteSupply(this);" pkSupId='+item.pkSupId+'  value="删除"  />
      	html+='<td class="lv">_option_href</td>';
      	if(item.supName.length>5){
          	html+='<td title="'+item.supName+'">'+item.supName.substring(0,5)+'...</td>';
      	}else{
          	html+='<td>'+item.supName+'</td>';
      	}
      	if(item.supInd.length>5){
          	html+='<td title="'+item.supInd+'">'+item.supInd.substring(0,5)+'...</td>';
      	}else{
          	html+='<td>'+item.supInd+'</td>';
      	}
      	html+='<td>'+item.conName+'</td>';
      	html+='<td>'+item.conMobile+'</td>';
      	if(item.deliverAddr.length>5){
      		html+='<td title="'+item.deliverAddr+'">'+item.deliverAddr.substring(0,5)+'...</td>';
      	}else{
      		html+='<td>'+item.deliverAddr+'</td>';
      	}
      	html+='<td>'+item.orderTime+'</td>';
      	html+=' <td>'+item.branName+'</td><td>'+item.userName+'</td><td>'+item.supStatus+'</td>';
      	html+='<td>_option_button</td>';
      	if(item.fkBranId==nowBranId&&updateFlag==true){
      		html=html.replace("_option_href", '<a href="#" onclick="forwardToUpdate(this);" passed="1"   pkSupId="'+item.pkSupId+'">'+item.pkSupId+'</a>');
      	}else{
      		html=html.replace("_option_href", '<a href="#" onclick="forwardToUpdate(this);" passed="0"  pkSupId="'+item.pkSupId+'">'+item.pkSupId+'</a>');
      	}
      	if(deleteFlag==true){
      	    html=html.replace("_option_button", '<input type="button" class="btn_l" onclick="deleteSupply(this);" pkSupId='+item.pkSupId+'  value="删除"  />');
      	}else{
      	    html=html.replace("_option_button", '');
      	}
		$("#showData").find("tr:eq("+index+")").after(html);
	});
}
/*无权限时查看**/
function readSupInfo(obj){
	var pkSupId=$(obj).attr("pkSupId");
	window.location.href="${basePath}scmInvocing/supplier/readSupInfo.shtml?pkSupId="+pkSupId+"";
}

//forward to update page
function forwardToUpdate(obj){
	var pkSupId=$(obj).attr("pkSupId");
	var  passed=$(obj).attr("passed");
	window.location.href="${basePath}scmInvocing/supplier/forwardToUpdateSuply.shtml?pkSupId="+pkSupId+"&passed="+passed+"";
}
function deleteSupply(obj){
	$.messager.confirm('温馨提示', '亲，确定要执行删除操作吗?', function(r) {
		if (r) {
			//检查当前供应商的状态，是否可以删除
			var pkSupId=$(obj).attr("pkSupId");
			$.ajax({
					url:"${basePath}scmInvocing/supplier/deleteBefore.shtml",
					dataType:"text",
					type:"post",
					async:true,
					data:{"fkSupId":pkSupId},
					error : function(XMLHttpRequest) {
      	 				ajaxError(XMLHttpRequest);
      	 			},
					success:function(result){
						if(result=="ok"){
							$.ajax({
								url:"${basePath}scmInvocing/supplier/deleteSupply.shtml",
								dataType:"text",
								type:"post",
								async:false,
								data:{"pkSupId":pkSupId},
								error : function(XMLHttpRequest) {
			      	 				ajaxError(XMLHttpRequest);
			      	 			},
								success:function(result){
									alertInfo($common_delete_success);
									initParams();
								}
						 });
						}else if(result=="passed"){
								//有人在使用中
								alertInfo("该数据正在使用中，不允许删除!");
								return;
						}else{
							$.messager.confirm('温馨提示', '该项数据可能正在使用中，你确定要删除?', function(r) {
							if(r){
								$.ajax({
									url:"${basePath}scmInvocing/supplier/deleteSupply.shtml",
									dataType:"text",
									type:"post",
									async:false,
									data:{"pkSupId":pkSupId},
									error : function(XMLHttpRequest) {
				      	 				ajaxError(XMLHttpRequest);
				      	 			},
									success:function(result){
										alertInfo($common_delete_success);
										initParams();
									}
								});		
								
							
							}
							});
						}
				 }
				
			});
		
		}
	});
}
//查询符合条件的供应商信息
function findSupplyInfo(){
	initParams();	
}
//跳转重定向
function redirect(url){
	window.location.href=url;
}
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    		<shiro:hasPermission name="scmInvocing/productInfo/forwardToProductInfo.shtml">
    				  <li ><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
    		</shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/countUnit/forwardToUnitInfo.shtml">
    		 		<li><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
    		 </shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/supplier/forwardToSupply.shtml">
    		 		   <li class="content_hover"><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
    		 </shiro:hasPermission>
    		  <shiro:hasPermission name="scmInvocing/priceManager/forwardToList.shtml">
    		 		  <li><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPurOrder/findInvoPurOrder.shtml">
            	  <li><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPayForm/findInvoOrderPay.shtml">
           		   <li><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
    		 </shiro:hasPermission>
   		</ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
    	<div class="file_single_dl f14 fixed">
    		<form id="supplyInfo" action="${basePath}scmInvocing/supplier/findSupplyInfo.shtml">
    		<input type="hidden" name="pageNo" id="pageNo" value="1">
    		<input type="hidden" name="pageSize" id="pageSize" value="8">
        	<dl class="fixed" style="overflow:hidden">
            	<dd><label>供应商名称：</label><input type="text" class="iput_t w200" name="supName"></dd>
                <dd>
                	<input type="button" class="btn ml10" value="查询" onclick="findSupplyInfo();">
                	<shiro:hasPermission name="supply:add">
                			    <input class="btn ml10" type="button" value="新增" onclick="redirect('${basePath}scmInvocing/supplier/forwardToAddSuply.shtml');"/>
                	</shiro:hasPermission>
                </dd>
            </dl>
            </form>
        </div>
       
        <div class="mt10">
          	<ul class="fixed" id="tab_conbox_a">
                <li class="p10" style="margin-left:10px">
                	<table class="table" id="showData">
                    	<tr>
                        	<th>序号</th>
                            <th>供应商编号</th>
                            <th>供应商名称</th>
                            <th>所属行业</th>
                            <th>联系人</th>
                            <th>联系方式</th>
                            <th>收货地址</th>
                            <th>制单日期</th>
                            <th>制单单位</th>
                            <th>制单人</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                      
                    </table>
                    <!---翻页-->
                    <div class="page fr m10"  id="foot">
                    	
                    </div>
                    <!----->
                </li>
                </ul>
                </div>
        </div>
    </div>
</div>

</body>
</html>

